<?php



/**
 * Klasa generująca elementy formularza służacego do włączania filtrów w grupie
 * 
 * @author strange3studio
 *
 */
class GcPriceSortGroupEditionFormHandler implements IGcFilterFormPreparationHandler {
  
  // group id that need Filtration Form
  private $_gid;

  public function generateForm() {

    $sql = db_query("SELECT filter_by_price_sort
                     FROM {gcf_price_sort} WHERE gnid=%d",$this->_gid);
    
    $result = db_fetch_object($sql);
    
    $form['filter_by_price_sort'] = array(
	    '#type' => 'checkbox',
	    '#title' => t('Apply price sorting filter'),
	    '#default_value' => $result->filter_by_price_sort
    );
    
    return $form;
  }
  
  public function submitForm(&$form) {
  	
	  $filter_value = $form['nid']['#post']['filter_by_price_sort'];
	  $gnid = $form['nid']['#value'];
	  
      
    db_query(
              "DELETE FROM {gcf_price_sort} WHERE gnid = %d",
              $gnid
            ); 
            
    db_query(
              "INSERT INTO {gcf_price_sort} VALUES (%d,%d)",
              $gnid,  
              $filter_value
            );  
   
  
  }
  
  public function __construct($gid = NULL) {
    $this->_gid = $gid;
  }

  
}